package src.com.servlet;

import src.com.service.MyService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.util.Enumeration;
import java.util.List;

public class GetSentenceCoordinate extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ResultSet rs = null;
        String pageNum = null;
        Enumeration paramNames = req.getParameterNames();     //将所有请求参数名称保存到一个枚举对象进行返回，枚举对象的遍历与迭代器类似
        while(paramNames.hasMoreElements()) {
            String paraname = paramNames.nextElement().toString();          //获取请求参数的名字
            pageNum = req.getParameter(paraname);
        }
        //System.out.println(pageNum);
        MyService myService = new MyService();
        List<String[]> data = myService.getSentenceCoordinate(Integer.parseInt(pageNum));

        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html");
        PrintWriter out = resp.getWriter();

        if(!data.isEmpty()){
            System.out.println("GetSentenceCoordinateLet中的集合不为空");
            out.print(data.size()+",");
            for(int i=0;i<data.size();i++){
                String []temp = new String[15];
                temp = data.get(i);
                out.print(temp[0].trim());
                out.print(",");
                out.print(temp[1].trim());
                out.print(",");
                out.print(temp[2].trim());
                out.print(",");

                out.print(temp[6].trim());
                out.print(",");
                out.print(temp[9].trim());
                out.print(",");
                out.print(temp[10].trim());
                out.print(",");
                out.print(temp[13].trim());
                out.print(",");
                out.print(temp[14].trim());
                out.print(",");
            }
            out.flush();
            out.close();
        }
    }
}
